﻿//#define ORACLE
//#define ORACLE92
//#define ORACLE10
#define SQLSERVER
//#define SQLSERVER2005
//#define SQLSERVER2012
//#define INSTALL_METADATA
//#define INSTALL_APPUSER

using System;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using Centido.Core;
using Centido.Core.Dto;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //foreach (var row in DbProviderFactories.GetFactoryClasses().Rows)
            //{
            //    Console.WriteLine(((DataRow)row)[2]);
            //}

            //return;


#if ORACLE
            var installer = new OracleInstaller("Driver={Oracle in OraClient11g_home1};dbq=localhost:1521/orcl;Uid=SYS;Pwd=Strong5554912 AS SYSDBA",
                                                "ORACLE");
#endif
#if ORACLE92
            var installer = new OracleInstaller("Driver={Oracle in XE};dbq=192.168.1.38:1521/ORACLE92;Uid=SYS;Pwd=Strong5554912 AS SYSDBA",
                                                "ORACLE");
#endif
#if ORACLE10
            var installer = new OracleInstaller("Driver={Oracle in XE};dbq=ec2-50-17-118-106.compute-1.amazonaws.com:1521/orcl;Uid=SYS;Pwd=Strong5554912 AS SYSDBA",
                                                "ORACLE");
#endif
#if SQLSERVER
            var installer = new SqlServerInstaller(@"Driver={SQL Server};Server=.\SQLEXPRESS;Uid=sa;Pwd=Strong5554912;",
                                                "MSSQLSERVER");
#endif
#if SQLSERVER2005
            var installer = new SqlServerInstaller(@"Driver={SQL Server};Server=.\SQLEXPRESS2005;Uid=sa;Pwd=Strong5554912;",
                                                "SQL Server");

#endif
#if SQLSERVER2012
            var installer = new SqlServerInstaller(@"Driver={SQL Server};Server=.\SQLEXPRESS2012;Uid=sa;Pwd=Strong5554912;",
                                                "SQL Server");

#endif
#if INSTALL_METADATA
            installer.CreateAppUser("CENTIDO", "Strong5554912", "MyDb");
#endif
#if ORACLE
            installer.DbConnectionString = "Driver={Oracle in OraClient11g_home1};"
                + "dbq=localhost:1521/orcl;Uid=CENTIDO;Pwd=Strong5554912";
#endif
#if ORACLE92
            installer.DbConnectionString = "Driver={Oracle in XE};dbq=192.168.1.38:1521/ORACLE92;Uid=CENTIDO;Pwd=Strong5554912";

#endif
#if ORACLE10
            installer.DbConnectionString = "Driver={Oracle in XE};dbq=ec2-50-17-118-106.compute-1.amazonaws.com:1521/orcl;Uid=CENTIDO;Pwd=Strong5554912";
#endif
#if SQLSERVER
            installer.DbConnectionString = @"Driver={SQL Server};Server=.\SQLEXPRESS;Database=MyDb;Uid=sa;Pwd=Strong5554912;";
#endif
#if SQLSERVER2005
            installer.DbConnectionString = @"Driver={SQL Server};Server=.\SQLEXPRESS2005;Uid=CENTIDO;Pwd=Strong5554912;";
#endif
#if SQLSERVER2012
            installer.DbConnectionString = @"Driver={SQL Server};Server=.\SQLEXPRESS2012;Uid=CENTIDO;Pwd=Strong5554912;";
#endif
#if INSTALL_METADATA
            installer.Install();

            return;
#endif

#if SQLSERVER || SQLSERVER2005 || SQLSERVER2012
            var config = new DomainConfiguration()
                             {
                                 DbConnectionString =
                                     new SqlServerConnectionStringBuilder
                                         {
                                             Driver = "SQL Server",
#if SQLSERVER
                                             Host = @".\SQLEXPRESS",
#endif
#if SQLSERVER2005
                                             Host = @".\SQLEXPRESS2005",
#endif
#if SQLSERVER2012
                                             Host = @".\SQLEXPRESS2012",
#endif
                                             DbName = "MyDb",
#if INSTALL_APPUSER
                                             UserName = "CENTIDO",
#else
                                             UserName = "admin",
#endif
                                             UserPassword = "Strong5554912"
                                         }.Build(),
                                 DbProviderName = "MSSQLSERVER",
                                 DbSchemaName = "dbo"
                             };
#endif

#if ORACLE || ORACLE92 || ORACLE10
            var config = new DomainConfiguration()
            {

                DbConnectionString = ""
#if ORACLE
 + "Driver={Oracle in OraClient11g_home1};dbq=localhost:1521/orcl;"
#endif
#if ORACLE92
 + "Driver={Oracle in XE};dbq=192.168.1.38:1521/ORACLE92;"
#endif
#if ORACLE10
 + "Driver={Oracle in XE};dbq=ec2-50-17-118-106.compute-1.amazonaws.com:1521/orcl;"
#endif
#if INSTALL_APPUSER
 + "Uid=CENTIDO;Pwd=Strong5554912;",
#else
 + "Uid=admin;Pwd=Strong5554912;",
#endif
                DbProviderName = "ORACLE",
                DbSchemaName = "CENTIDO"
            };
#endif

#if INSTALL_APPUSER
            var appDomain = Domain.Build(config);

            var admin = appDomain.AddUser("admin", "Strong5554912");
            admin.CanChangeSchema = true;
            admin.CanChangeSecurity = true;

            return;
#endif
            var domain = Domain.Build(config);

            domain.DeleteAll();

            var table = domain.AddTable("my_table");

            var column = table.AddColumn("my_col", ColumnType.Integer);

            table.AddIndex(true, column);
        }
    }
}
